<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <template v-for="(po,index) in queryColumns">
            <template v-if="po.hidden==='1'">
              <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="po.mode=='single'" v-show="toggleSearchStatus">
                <a-form-item :label="po.dbFieldTxt">
                  <j-search-select-tag v-if="po.fieldShowType =='sel_search'" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]" :dict="po.dictTable+','+po.dictText+','+po.dictField+','+po.condition"/>
                  <j-select-user-by-dep v-else-if="po.fieldShowType =='sel_user'" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]"/>
                  <j-select-depart v-else-if="po.fieldShowType =='sel_depart'" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]"/>
                  <j-multi-select-tag v-else-if="po.fieldShowType=='list_multi'" :placeholder="'请选择'+po.dbFieldTxt" :dictCode="po.dictTable+','+po.dictText+','+po.dictField+','+po.condition" v-model="queryParam[po.dbFieldName]"/>
                  <j-category-select v-else-if="po.fieldShowType =='cat_tree'" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]" :pcode="po.oldDictTable"/>
                  <j-date v-else-if="po.fieldShowType =='date'" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]"></j-date>
                  <j-date v-else-if="po.fieldShowType =='datetime'" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]"></j-date>
                  <j-popup v-else-if="po.fieldShowType =='popup'"
                           :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]"
                           :code="po.dictTable" :org-fields="po.dictField" :dest-fields="po.dictText"
                           :field="po.dictText"/>

                  <j-dict-select-tag v-else-if="po.fieldShowType=='list' || po.fieldShowType=='radio' || po.fieldShowType=='checkbox'" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]" :dictCode="po.dictTable+','+po.dictText+','+po.dictField+','+po.condition"/>
                  <a-input v-else :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]" />
                </a-form-item>
              </a-col>
              <a-col :xl="12" :lg="11" :md="16" :sm="24" v-if="po.mode!='single'" v-show="toggleSearchStatus">
                <a-form-item :label="po.dbFieldTxt">
                  <template v-if="po.fieldShowType =='date'">
                    <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam[po.dbFieldName+'_fld0_value']"></j-date>
                    <span class="query-group-split-cust"></span>
                    <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam[po.dbFieldName+'_fld1_value']"></j-date>
                  </template>
                  <template v-else-if="po.fieldShowType =='datetime'">
                    <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam[po.dbFieldName+'_fld0_value']"></j-date>
                    <span class="query-group-split-cust"></span>
                    <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam[po.dbFieldName+'_fld1_value']"></j-date>
                  </template>
                  <template v-else>
                    <a-input placeholder="请输入最小值" class="query-group-cust" v-model="queryParam[po.dbFieldName+'_fld0_value']"></a-input>
                    <span class="query-group-split-cust"></span>
                    <a-input placeholder="请输入最大值" class="query-group-cust" v-model="queryParam[po.dbFieldName+'_fld1_value']"></a-input>
                  </template>
                </a-form-item>
              </a-col>
            </template>
            <template v-else-if="!po.hidden">
              <a-col :xl="6" :lg="7" :md="8" :sm="24" v-if="po.mode=='single'">
                <a-form-item :label="po.dbFieldTxt">
                  <j-search-select-tag v-if="po.fieldShowType =='sel_search'" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]" :dict="po.dictTable+','+po.dictText+','+po.dictField+','+po.condition"/>
                  <j-select-user-by-dep v-else-if="po.fieldShowType =='sel_user'" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]"/>
                  <j-select-depart v-else-if="po.fieldShowType =='sel_depart'" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]"/>
                  <j-multi-select-tag v-else-if="po.fieldShowType=='list_multi'" :placeholder="'请选择'+po.dbFieldTxt" :dictCode="po.dictTable+','+po.dictText+','+po.dictField+','+po.condition" v-model="queryParam[po.dbFieldName]"/>
                  <j-category-select v-else-if="po.fieldShowType =='cat_tree'" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]" :pcode="po.oldDictTable"/>
                  <j-date v-else-if="po.fieldShowType =='date'" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]"></j-date>
                  <j-date v-else-if="po.fieldShowType =='datetime'" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]"></j-date>
                  <j-popup v-else-if="po.fieldShowType =='popup'"
                           :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]"
                           :code="po.dictTable" :org-fields="po.dictField" :dest-fields="po.dictText"
                           :field="po.dictText"/>

                  <j-dict-select-tag v-else-if="po.fieldShowType=='list' || po.fieldShowType=='radio' || po.fieldShowType=='checkbox'" :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]" :dictCode="po.dictTable+','+po.dictText+','+po.dictField+','+po.condition"/>
                  <a-input v-else :placeholder="'请选择'+po.dbFieldTxt" v-model="queryParam[po.dbFieldName]" />
                </a-form-item>
              </a-col>
              <a-col :xl="12" :lg="11" :md="16" :sm="24" v-if="po.mode!='single'">
                <a-form-item :label="po.dbFieldTxt">
                  <template v-if="po.fieldShowType =='date'">
                    <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam[po.dbFieldName+'_fld0_value']"></j-date>
                    <span class="query-group-split-cust"></span>
                    <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam[po.dbFieldName+'_fld1_value']"></j-date>
                  </template>
                  <template v-else-if="po.fieldShowType =='datetime'">
                    <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam[po.dbFieldName+'_fld0_value']"></j-date>
                    <span class="query-group-split-cust"></span>
                    <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam[po.dbFieldName+'_fld1_value']"></j-date>
                  </template>
                  <template v-else>
                    <a-input placeholder="请输入最小值" class="query-group-cust" v-model="queryParam[po.dbFieldName+'_fld0_value']"></a-input>
                    <span class="query-group-split-cust"></span>
                    <a-input placeholder="请输入最大值" class="query-group-cust" v-model="queryParam[po.dbFieldName+'_fld1_value']"></a-input>
                  </template>
                </a-form-item>
              </a-col>
            </template>
          </template>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-if="buttonSwitch.add" @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button v-if="buttonSwitch.import" @click="handleImportXls" type="primary" icon="upload" style="margin-left:8px">导入</a-button>
      <a-button v-if="buttonSwitch.export" @click="handleExportXls" type="primary" icon="download" style="margin-left:8px">导出</a-button>
      <template v-if="cgButtonList && cgButtonList.length>0" v-for="(item,index) in cgButtonList">
        <a-button
          v-if=" item.optType=='js' "
          :key=" 'cgbtn'+index "
          @click="cgButtonJsHandler(item.buttonCode)"
          type="primary"
          :icon="item.buttonIcon"
          style="margin-left:8px">
          {{ item.buttonName }}
        </a-button>
        <a-button
          v-else-if=" item.optType=='action' "
          :key=" 'cgbtn'+index "
          @click="cgButtonActionHandler(item.buttonCode)"
          type="primary"
          :icon="item.buttonIcon"
          style="margin-left:8px">
          {{ item.buttonName }}
        </a-button>
      </template>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="pagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio'}"
        :customRow="clickThenSelect"
        @change="handleTableChange">

        <template slot="dateSlot" slot-scope="text">
          <span>{{ getDateNoTime(text) }}</span>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadRowFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <template v-if="showOptButton('update',record)">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item v-if="showOptButton('delete',record)">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <a-tabs defaultActiveKey="1">
      <template v-for="(sub,index) in subColumns">
        <a-tab-pane :tab="sub.description" :key="sub.currentTableName" :forceRender="sub.forceRender">
          <oufuform-erp-child-list :mainId="selectedMainId" :main="sub" :parentCode="code"/>
        </a-tab-pane>
      </template>
    </a-tabs>
    <oufuform-erp-modal ref="modal" @ok="modalFormOk" :code="code"></oufuform-erp-modal>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import {initDictOptions,filterDictText,filterMultiDictText} from '@/components/dict/JDictSelectUtil'
import OufuformErpModal from './modules/OufuformErpModal'
import { getAction,postAction,deleteAction,downFile } from '@/api/manage'
import OufuformErpChildList from './OufuformErpChildList'
import { filterObj } from '@/utils/util';
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
import JDate from '@/components/jeecg/JDate.vue'
import { loadCategoryData } from '@/api/api'
import JInput from '@comp/jeecg/JInput'
import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'
import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
import JMultiSelectTag from '@/components/dict/JMultiSelectTag'
import JCategorySelect from '@comp/jeecg/JCategorySelect'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
import JPopup from '@comp/jeecg/JPopup'
import '@/assets/less/TableExpand.less'
  export default {
    name: "OufuformAutoErpList",
    mixins:[JeecgListMixin],
    components: {
      JSuperQuery,
      JDictSelectTag,
      JDate,
      JInput,
      JPopup,
      JSelectUserByDep,
      JSelectDepart,
      JMultiSelectTag,
      JCategorySelect,
      JSearchSelectTag,
      OufuformErpModal,
      OufuformErpChildList
    },
    data () {
      return {

        disableMixinCreated:true,
        description: '管理页面',
        // 表头
        columns: [],
        //查询头
        queryColumns:[],
        //子表
        subColumns:[],
        //数据集
        dataSource: [],
        // 选择器
        selectedRowKeys: [],
        selectionRows: [],
        loading: false,
        url: {
          getQueryInfo: '/online/cgform/autoGetQueryInfo',
          getFormItems: '/online/cgform/autoGetFormItem',
          getColumns: '/online/cgform/autoGetErpColumns',
          getData: '/online/cgform/public/autoGetData',
          delete: '/online/cgform/public/autoDeleteForm',
          exportXls: '/online/cgform/autoExportXls',
          buttonAction: '/online/cgform/autoDoButton',
        },
        isorter:{
          column: 'id',
          order: 'desc',
        },
        dictOptions:{},
        /* 分页参数 */
        pagination:{
          current: 1,
          pageSize: 5,
          pageSizeOptions: ['5', '10', '50'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        queryParam:{
        },
        actionColumn:{
          title: '操作',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
          fixed:"right",
          align:"center",
          width:150
        },
        formTemplate:"99",
        /*自定义按钮-link*/
        cgButtonLinkList:[],
        /*自定义按钮-button*/
        cgButtonList:[],
        /*JS增强*/
        EnhanceJS:'',
        /*操作按钮权限*/
        buttonSwitch:{
          add:true,
          update:true,
          delete:true,
          batch_delete:true,
          import:true,
          export:true
        },
        selectedMainId:''
      }
    },
    created() {
      this.initAutoListConfig().then(()=>{
        this.loadData(1)
      }).catch(msg=>{
        console.log(msg)
      })
    },
    watch: {
      '$route'() {
        // 刷新参数放到这里去触发，就可以刷新相同界面了
        this.initAutoListConfig().then(()=>{
          this.loadData(1)
        }).catch(msg=>{
          console.log(msg)
        })
      }
    },
    methods: {
      initAutoListConfig() {
        return new Promise((resolve, reject) => {
          if (!this.$route.params.code) {
            reject("列表加载需要参数CODE为空!")
          } else {
            this.loading = true
            this.code = this.$route.params.code
            //查询列表字段
            getAction(`${this.url.getColumns}`, {autoHeadId: this.code}).then(res => {
              //console.log("--onlineList-加载动态列>>", res);
              if (res.success) {
                //查询字段
                getAction(`${this.url.getQueryInfo}`, {autoHeadId: this.code}).then(res2 => {
                  this.configQueryhandler(res2)
                })
                this.configInfohandler(res)
                resolve();
              } else {
                reject("onlineList-加载表配置信息失败")
              }
              this.loading = false
            }).catch(err => {
              reject(err)
            })

            //表单字段
          }
        })
      },
      configQueryhandler(res){
        let currColumns = res.result
        this.queryColumns = currColumns;
        this.queryColumns.forEach((po,index)=>{
          if(po.mode!='single'){
            this.queryParam[po.dbFieldName+'_fld0_op'] ='greaterThanEqualTo';
            this.queryParam[po.dbFieldName+'_fld1_op'] ='lessThanEqualTo';
          }
        })
      },
      configInfohandler(res){
        let main = res.result.main;
        this.dictOptions = main.dictOptions
        this.formTemplate = main.formTemplate
        this.description = main.description
        //自定义按钮
        this.initCgButtonList(main.cgButtonList)
        //JS增强
        this.initCgEnhanceJs(main.enhanceJs)
        //操作按钮权限
        this.initButtonSwitch(main.hideColumns)
        let currColumns = main.columns
        let textFieldIndex = -1
        let hasBpmStatus = false
        for (let a = 0; a < currColumns.length; a++) {
          currColumns[a].align = 'left'
          //找到显示列
          if (this.textField == currColumns[a].dataIndex) {
            textFieldIndex = a
          }
          //数据字典翻译
          if (currColumns[a].customRender) {
            let dictCode = currColumns[a].customRender;
            currColumns[a].customRender = (text) => {
              return filterMultiDictText(this.dictOptions[dictCode], text);
            }
          }

          //判断是否有bpm_status
          if (currColumns[a].dataIndex.toLowerCase() == 'bpm_status') {
            hasBpmStatus = true;
          }
        }
        this.hasBpmStatus = hasBpmStatus;
        if (textFieldIndex != -1) {
          let textFieldColumn = currColumns.splice(textFieldIndex, 1)
          currColumns.unshift(textFieldColumn[0])
        }
        currColumns.push(this.actionColumn);
        this.columns = [...currColumns]

        //处理子表
        this.subColumns = res.result.subList;
      },

      loadData(arg){
        if (arg == 1) {
          this.pagination.current = 1
        }
        this.onClearSelected()
        this.loading = true
        let params = this.getQueryParams();//查询条件
        params.autoHeadId = this.code;
        getAction(`${this.url.getData}`, params).then((res) => {
          if (res.success) {
            let result = res.result;
            if (Number(result.total) > 0) {
              this.pagination.total = Number(result.total)
              let dataSource = res.result.records;
              this.dataSource = dataSource
            } else {
              this.pagination.total = 0;
              this.dataSource = []
            }
          } else {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },
      getQueryParams() {
        let param = Object.assign({}, this.queryParam, this.isorter);
        param.pageNo = this.pagination.current;
        param.pageSize = this.pagination.pageSize;
        return filterObj(param);
      },
      initCgButtonList(btnList){
        let linkArr = []
        let buttonArr = []
        if (btnList && btnList.length > 0) {
          for (let i = 0; i < btnList.length; i++) {
            let temp = btnList[i]
            if (temp.buttonStyle == 'button') {
              buttonArr.push(temp)
            } else if (temp.buttonStyle == 'link') {
              linkArr.push(temp)
            }
          }
        }
        this.cgButtonLinkList = [...linkArr]
        this.cgButtonList = [...buttonArr]
      },
      initCgEnhanceJs(enhanceJs){
        //console.log("--onlineList-js增强",enhanceJs)
        if (enhanceJs) {
          let Obj = eval("(" + enhanceJs + ")");
          this.EnhanceJS = new Obj(getAction, postAction, deleteAction);
          this.cgButtonJsHandler('created')
        } else {
          this.EnhanceJS = ''
        }
      },
      initButtonSwitch(hideColumns){
        if (hideColumns && hideColumns.length > 0) {
          Object.keys(this.buttonSwitch).forEach(key => {
            if (hideColumns.indexOf(key) >= 0) {
              this.buttonSwitch[key] = false
            }
          })

        }
      },

      clickThenSelect(record) {
        return {
          on: {
            click: () => {
              this.onSelectChange(record.id.split(","), [record]);
            }
          }
        }
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.selectedMainId=''
      },
      handleTableChange(pagination, filters, sorter){
        //TODO 筛选
        if (Object.keys(sorter).length > 0) {
          this.isorter.column = sorter.field;
          this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
        }
        this.pagination = pagination;
        this.loadData();
      },
      getDateNoTime(text){
        if (!text) {
          return ''
        }
        let a = text;
        if (a.length > 10) {
          a = a.substring(0, 10);
        }
        return a;
      },
      getImgView(text){
        if (text && text.indexOf(",") > 0) {
          text = text.substring(0, text.indexOf(","))
        }
        return window._CONFIG['staticDomainURL'] + "/" + text
      },
      downloadRowFile(text){
        if (!text) {
          this.$message.warning("未知的文件")
          return;
        }
        if (text.indexOf(",") > 0) {
          text = text.substring(0, text.indexOf(","))
        }
        window.open(window._CONFIG['staticDomainURL'] + "/" + text);
      },
      handleEdit(record){
        this.cgButtonLinkHandler(record, "beforeEdit", "js")
        this.$refs.modal.edit(record);
      },
      handleDeleteOne(record){
        this.cgButtonLinkHandler(record, "beforeDelete", "js")
        this.handleDelete(record.id)
      },
      handleDelete(id){
        deleteAction(this.url.delete, {autoHeadId: this.code, id: id}).then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData()
          } else {
            this.$message.warning(res.message)
          }
        })
      },
      handleAdd(record){
        this.loadParent = true
        this.cgButtonJsHandler('beforeAdd');
        let obj = {}
        this.$refs.modal.add(obj);
      },
      modalFormOk(formData, arr){
        this.loadData(1);
      },
      handleImportXls(){
        this.$refs.importModal.show()
      },
      importOk(){
        this.loadData(1)
      },
      getImportUrl(){
        return '/online/cgform/autoImportXls?autoHeadId=' + this.code
      },
      handleExportXls(){
        let param = this.queryParam;
        if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
          param['selections'] = this.selectedRowKeys.join(",")
        }
        console.log("导出参数", param)
        let paramsStr = JSON.stringify(filterObj(param));
        paramsStr.autoHeadId = this.code;
        downFile(this.url.exportXls, {paramsStr: paramsStr}).then((data) => {
          if (!data) {
            this.$message.warning("文件下载失败")
            return
          }
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(new Blob([data]), this.description + '.xls')
          } else {
            let url = window.URL.createObjectURL(new Blob([data]))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', this.description + '.xls')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link); //下载完成移除元素
            window.URL.revokeObjectURL(url); //释放掉blob对象
          }
        })
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedMainId=selectedRowKeys[0]
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
      cgButtonLinkHandler(record, buttonCode, optType){
        if (optType == "js") {
          if (this.EnhanceJS[buttonCode]) {
            this.EnhanceJS[buttonCode](this, record)
          }
        } else if (optType == "action") {
          let params = {
            formId: this.code,
            buttonCode: buttonCode,
            dataId: record.id
          }
          console.log("自定义按钮link请求后台参数：", params)
          postAction(this.url.buttonAction, params).then(res => {
            if (res.success) {
              this.loadData()
              this.$message.success("处理完成!")
            } else {
              this.$message.warning("处理失败!")
            }
          })
        }
      },
      cgButtonJsHandler(buttonCode){
        if (this.EnhanceJS[buttonCode]) {
          this.EnhanceJS[buttonCode](this)
        }
      },
      cgButtonActionHandler(buttonCode){
        //处理自定义button的 需要配置该button自定义sql
        if (!this.selectedRowKeys || this.selectedRowKeys.length == 0) {
          this.$message.warning("请先选中一条记录")
          return false
        }
        if (this.selectedRowKeys.length > 1) {
          this.$message.warning("请只选中一条记录")
          return false
        }
        let params = {
          formId: this.code,
          buttonCode: buttonCode,
          dataId: this.selectedRowKeys[0]
        }
        console.log("自定义按钮请求后台参数：", params)
        postAction(this.url.buttonAction, params).then(res => {
          if (res.success) {
            this.loadData()
            this.$message.success("处理完成!")
          } else {
            this.$message.warning("处理失败!")
          }
        })

      },
      /*-------JS增强-end----------*/
      showOptButton(opt, record){
        //只有当按钮属性为false,或是按钮属性为true但是流程已提交时才隐藏
        if (!this.buttonSwitch[opt]) {
          return false
        } else {
          if (this.hasBpmStatus) {
            if (record.bpm_status != null && record.bpm_status != '' && record.bpm_status != '1') {
              return false
            }
          }
        }
        return true
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>